SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE dbo.[DnnProduct_CDS_CategoriesDelete]
	@ID int
AS
BEGIN
	IF NOT EXISTS(SELECT * FROM [DnnProduct_CDS_Assets] WHERE CategoryID = @ID)
	BEGIN
		IF NOT EXISTS(SELECT * FROM [DnnProduct_CDS_Categories] WHERE ParentID = @ID)
		BEGIN
			DELETE FROM [DnnProduct_CDS_Categories]
			WHERE [ID] = @ID AND [IsReadOnly] = 0
		END
	END
END
GO
